package com.stormrage.edu.dao.learn.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.learn.LeaBunchApplyDao;
import com.stormrage.entity.learn.LeaBunchApply;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: LeaBunchApplyDaoImpl.java
 * @Package com.stormrage.edu.dao.learn.impl
 * @Description: 班级报名 Dao
 * @author www.stormragetech.com
 * @date 2016年4月15日
 * @version V1.0
 */
@Repository
public class LeaBunchApplyDaoImpl extends MysBaseDao implements LeaBunchApplyDao {

	private static final Logger logger = LoggerFactory.getLogger(LeaBunchApplyDaoImpl.class);

	@Override
	public void updateLock(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 updateLock 】- 开始运行 ");

		final String query = "UPDATE lea_bunch_apply SET locked = 1 WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 updateLock 】- 完成运行 ");

	}

	@Override
	public void updateLockToSchedule(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 updateLockToSchedule 】- 开始运行 ");

		final String query = "UPDATE lea_bunch_apply SET locked = 2 WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 updateLockToSchedule 】- 完成运行 ");

	}

	@Override
	public void deletebyBunch(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 deletebyBunch 】- 开始运行 ");

		final String query = "DELETE FROM lea_bunch_apply WHERE bunch_id = :bunchId";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 deletebyBunch 】- 完成运行 ");

	}

	@Override
	public LeaBunchApply queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryById 】- 开始运行 ");

		final String query = "SELECT * FROM lea_bunch_apply WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		LeaBunchApply entity = queryObject(query, LeaBunchApply.class, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryById 】- 完成运行 ");
		return entity;

	}

	@Override
	public List<LeaBunchApply> queryByLock(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryByLock 】- 开始运行 ");

		final String query = "SELECT * FROM lea_bunch_apply WHERE locked = :locked";
		logger.debug(" 数据库执行语句为 " + query);

		List<LeaBunchApply> array = queryList(query, LeaBunchApply.class, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryByLock 】- 完成运行 ");
		return array;

	}

	@Override
	public List<LeaBunchApply> queryByBunchId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryById 】- 开始运行 ");

		final String query = "SELECT * FROM lea_bunch_apply WHERE bunch_id = :bunchId";
		logger.debug(" 数据库执行语句为 " + query);

		List<LeaBunchApply> array = queryList(query, LeaBunchApply.class, map);

		logger.debug(" 【 Dao 】-【 LeaBunchApplyDao 】-【 queryById 】- 完成运行 ");
		return array;

	}

}
